import 'package:flutter/material.dart';
import 'package:flutter_module/app/app.dart';
import 'package:flutter_module/base/base.dart';
import 'package:flutter_module/state_bloc/page_bloc_state.dart';
import 'package:flutter_module/state_get/page_get_state.dart';
import 'package:flutter_module/state_native/page_native_state.dart';
import 'package:flutter_module/state_provider/page_provider_state.dart';
import 'package:flutter_module/state_riverpod/page_riverpod_state.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class PageStateView extends BaseStateWidget {
  BlocHomeIndexState blocHomeIndexState;

  PageStateView(this.blocHomeIndexState, {super.key});

  @override
  BaseState<BaseStateWidget> buildState() => PageState();
}

class PageState extends BaseState<PageStateView> {
  // 数据
  List<String> naviBottom = ["Native", "GetX", "Provider", "Riverpod", "BLoC"];

  // 状态
  // int index = 0;

  Row buildBottom() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: naviBottom
          .map(
            (item) => GestureDetector(
              onTap: () {
                // 修改下标状态
                setState(() {
                  // index = naviBottom.indexOf(item);
                  widget.blocHomeIndexState.upIndex(naviBottom.indexOf(item));
                });
              },
              child: Container(
                alignment: Alignment.center,
                height: 104.w,
                child: Text(item, style: TextStyle(color: naviBottom.indexOf(item) != widget.blocHomeIndexState.state ? Colors.black : Colors.blue)),
              ),
            ),
          )
          .toList(),
    );
  }

  /// 构建页面
  Widget buildPage(int index) {
    switch (index) {
      case 0:
        return PageNative();
      case 1:
        // return GetPage(GetPageController());
        return GetWidget();
      case 2:
        return PageProvideState();
      case 3:
        return PageRiverpodState();
      case 4:
        return PageStatelessBloc();
        // return PageBloc();
      default:
        return Container();
    }
  }

  @override
  Widget setContent(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        // 中间部分
        Expanded(child: buildPage(widget.blocHomeIndexState.state)),
        Container(height: 1.w, width: 750.w, color: Colors.grey),
        // 底部导航
        buildBottom(),
      ],
    );
  }
}
